'use strict';
module.exports = (app) => {
  // 订单表
  const { STRING, INTEGER, DECIMAL, DATE, TEXT, ENUM } = app.Sequelize;
  const Order = app.model.define('s_order', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    order_id: {
      type: STRING,
      comment: '订单id',
      unique: true,
    },
    user_id: {
      type: STRING,
      comment: '用户id',
    },
    project_id: {
      type: INTEGER,
      comment: '项目id',
    },
    shops_id: {
      type: STRING,
      comment: '商家id',
    },
    shops_name: {
      type: STRING,
      comment: '商家名称',
    },
    goods_info: {
      type: TEXT,
      comment: '商品组信息',
    },
    status: {
      type: ENUM('-1', '0', '1', '2', '3', '4', '5', '6', '7'),
      comment:
        '-1：已删除，0:已过期,1:已下单，2:已支付，3:已发货, 4:退货中，5:退款中，6:已完成，7：已取消',
      defaultValue: '1',
    },
    logistics: {
      type: INTEGER,
      comment: '物流id',
    },
    addr_id: {
      type: INTEGER,
      comment: '地址id',
    },
    invoice: {
      type: INTEGER,
      comment: '发票id',
    },
    total_price: {
      type: DECIMAL(10, 2),
      comment: '总价格',
    },
    mode_of_payment: {
      type: STRING,
      comment: '支付方式 (1 积分)',
    },
    payment: {
      type: INTEGER,
      comment: '支付id',
    },
    order_time: {
      type: STRING,
      comment: '下单时间',
    },
    payment_time: {
      type: STRING,
      comment: '支付时间',
    },
    await_payment_time: {
      type: STRING,
      comment: '等待支付时间',
    },
  });

  Order.associate = function () {
    // 一对一链接地址表
    app.model.Tables.Shop.Order.belongsTo(app.model.Tables.Shop.Address, {
      foreignKey: 'addr_id',
    });
  };

  return Order;
};
